#!/bin/bash

echo "+++++++++++++START+++++++++++++"
echo "+++++++++++++START+++++++++++++"

while true; do
  read -p "请输入 .tar.gz 文件的完整路径: " TAR_FILE

  if [ ! -f "$TAR_FILE" ]; then
    echo "错误: 指定的文件不存在: $TAR_FILE"
    continue
  fi
  break
done

while true; do
  read -p "请输入目标容器目录 (默认files，打开容器列表，容器名下面的</data/data/com.termux/容器目录>): " CONTAINER_DIR

  if [ -z "$CONTAINER_DIR" ]; then
  CONTAINER_DIR=files
done


cd ~
cd ~

tar -v -xzvf "$TAR_FILE" -C "../../$CONTAINER_DIR"

mv "../../$CONTAINER_DIR/data/data/com.termux/files/home" "../../$CONTAINER_DIR"
mv "../../$CONTAINER_DIR/data/data/com.termux/files/usr" "../../$CONTAINER_DIR"

rm -rf "../../$CONTAINER_DIR/data"

echo "系统恢复完成,请在切换系统，切换您的系统"